<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/04/11 20:58:15 $)
// $RCSfile: impex.troubleshooter.php,v $ : $Revision: 1.4 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Return the Total Pages for this Plugin
*/
function getPluginTotalPages7()
{
	return 2;
}

/**
* Run the specific page for plugin
*/
function runPluginPage7($page)
{
	global $impexDB, $_IMPEXHASH;

	// Import Troubleshooters
	if ($page == 1)
	{
		$_troubleshootercatid = _impexInsertTroubleshooterCat("General", "", "1");
		displayStatus("Created Troubleshooter Category: General");

		$troubleshooterlist = array();

		// Fetch old data first
		$impexDB->query("SELECT * FROM `asTroubleshooter` ORDER BY `id` ASC;");
		while ($impexDB->nextRecord())
		{
			_impexProcessSlashVariables($impexDB->Record);

			$troubleshooterlist[$impexDB->Record["id"]] = $impexDB->Record;
		}

		// Now Insert the new data
		foreach ($troubleshooterlist as $key=>$val)
		{
			$_troubleshooterid = _impexInsertTroubleshooter("1", $val["subject"], $val["contents"], $val["gorder"]);

			$_IMPEXHASH["trpointer"][$key] = $_troubleshooterid;

			displayStatus("Imported Troubleshooter Step: ".htmlspecialchars($val["subject"]));
		}



	// Import the Links
	} else if ($page == 2) {
		$troubleshooterlinks = array();
		$impexDB->query("SELECT * FROM `asTroubleshooterLink` ORDER BY `linkid` ASC;");
		while ($impexDB->nextRecord())
		{
			_impexProcessSlashVariables($impexDB->Record);

			$troubleshooterlinks[$impexDB->Record["linkid"]] = $impexDB->Record;
		}

		foreach ($troubleshooterlinks as $key=>$val)
		{
			$newparentid = intval($_IMPEXHASH["trpointer"][$val["parentid"]]);
			$newchildid = intval($_IMPEXHASH["trpointer"][$val["childid"]]);

			_impexInsertTroubleshooterLink("1", $newparentid, $newchildid);

			displayStatus("Imported Troubleshooter Link (Parent ID: ". $newparentid ." &lt;&gt; Child ID: ". $newchildid .")");
		}

		unset($_IMPEXHASH["trpointer"]);
	}
	
}
?>